var pic = 'https://img2.woyaogexing.com/2022/09/26/44285b4b684b40e1!400x400.jpg';
var vm = new Vue({
    el:"#app",
    data:{//负责定义响应式数据
        list:[
            {name:'秋刀鱼',price:88,pic,count:1},
            {name:'大黄鱼',price:77,pic,count:1},
            {name:'皮皮虾',price:99,pic,count:1},
        ]
    },
    methods:{//负责定义方法
        add(item){
            if(item.count <5) item.count++;
        },
        sub(item,index){
            if(item.count > 0){
                item.count--;
            }
            if(item.count == 0){
                this.list.splice(index,1);
            }
        },
        clean(){
            this.list = [];
        }
    },
    computed:{ 
        totalCount(){
            console.log('计算属性: totalCount 执行了');
            var sum = 0;
            this.list.forEach((item)=>{
                sum += item.count;
            })
            return sum;
        },
    
        totalPrice(){
            var sum = 0;
            this.list.forEach((item)=>{
                sum += item.count * item.price;
            })
            return sum;
        }
    }
})